<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <!-- show books list -->
    <ul>
      <li v-for="(book, index) in books" :key="index" style="display:block">
        {{index}}-{{book.name}}-{{book.author}}
      </li>
    </ul>
    <!-- form to add a book -->
    <form action="">
      输入书名：<input type="text" placeholder="book name" v-model="inputBook.name"><br>
      输入作者：<input type="text" placeholder="book author" v-model="inputBook.author"><br>
    </form>
    <button type="submit" @click="get_info()">submit</button>
  </div>
</template>

<script>
  export default {
    name: 'HelloWorld',
    data() {
      return {
        msg: 'Welcome to Your Vue.js App',
        // books list data
        books: [{
            name: 'test',
            author: 't'
          },
          {
            name: 'test2',
            author: 't2'
          }
        ],
        // book data in the form
        inputBook: {
          "name": "",
          "author": "",
        }
      }
    },
    methods: {
      loadBooks() {

      }, // load books list when visit the page
      get_info() {
        //this.info_loading = true
        const params = {
          test: this.inputBook.name,
        }
        this.$api.Home.getTest(params).then((res) => {
          //this.info_loading = false
          if (res.result) {
            console.log(res.data)
            alert(res.data)
          } else {
            console.log(res.result)
            alert(res.data)
          }
        })
      },
    },
    created: function() {
      this.loadBooks()
    }
  }
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  h1,
  h2 {
    font-weight: normal;
  }

  ul {
    list-style-type: none;
    padding: 0;
  }

  li {
    display: inline-block;
    margin: 0 10px;
  }

  a {
    color: #42b983;
  }
</style>
